/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.biblioteca.controlador;

import com.biblioteca.persistencia.Rol;
import com.biblioteca.servicio.RolServicio;
import com.google.appengine.api.datastore.Key;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.springframework.stereotype.Component;
import org.springframework.web.jsf.FacesContextUtils;

/**
 *
 * @author hellwolf
 */
@Component
public class RolConverter implements javax.faces.convert.Converter {

    
    private RolServicio rolServicio;
    
    private RolServicio getRolServicio(FacesContext context){
        return (RolServicio)FacesContextUtils.getWebApplicationContext(context).getBean("RolServicio"); 
    }

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object o) {
        String rdo = null;
        if (o instanceof Key) {
            Key keyRol = (Key) o;
            Rol p = getRolServicio(FacesContext.getCurrentInstance()).getRol(keyRol);          
            if (p != null) {
                rdo = p.getNombre().toString();                
            }else{
            }
        }else{
        }
        return rdo;
    }
    
}
